-
Notifications
You must be signed in to change notification settings - Fork 46
CBOR bindings #559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
CBOR bindings #559
Conversation
awscrt/cbor.py
Outdated
return _awscrt.cbor_encoder_get_encoded_data(self._binding) | ||
|
||
def write_int(self, val: int): | ||
# TODO: maybe not support bignum for now. Not needed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
smithy currently does not support anything above 64bits afaik so we can probably skip bignum for now
awscrt/cbor.py
Outdated
# For negative value, the value to encode is -1 - val. | ||
val_to_encode = -1 - val | ||
bit_len = val_to_encode.bit_length() | ||
if bit_len > 64: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldnt python need 65 bits to represent - u64_max? so this logic might be a bit off, since we dont need bignum for - u64_max
awscrt/cbor.py
Outdated
Args: | ||
val (int): value to be encoded and written to the encoded data. | ||
""" | ||
assert isinstance(val, int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for my education, havent we already indicated in function signature htat val is an int? why do we have to check twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function signature is just a type hint, it won't enforce anything for runtime
https://docs.python.org/3/library/typing.html
Note
The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as type checkers, IDEs, linters, etc.
awscrt/cbor.py
Outdated
|
||
def write_array_start(self, number_entries: int): | ||
"""Add a start of array element. | ||
A legistic with the `number_entries` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
Args: | ||
number_entries (int): number of entries in the array to be written | ||
""" | ||
if number_entries < 0 or number_entries > 2**64: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh, cbor spec allows 2^64 entries? not sure we would be able to allocate cbor chunk for that even if all entries are 1 byte. should we consider a lower bound
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation will not allocate the whole array, it appends to the buffer when user keeps writing to it. So, the size of the array won't cause any allocation problem.
accidental approve. comments still need to be discussed
…on into cbor-remove-py-impl
…on into cbor-remove-py-impl
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.